package com.lottery.im.module.main.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import com.lottery.im.constant.Constants;
import com.lottery.im.module.chat.ui.ChatActivity;
import com.lottery.im.module.tim.event.RefreshEvent;
import com.lottery.im.util.AppManagerUtil;
import com.tencent.imsdk.TIMConversationType;
import com.tencent.imsdk.ext.message.TIMManagerExt;

/**
 * 点击通知栏消息，中转界面
 * 作用：用来判断 MainActivity是否已经打开
 */
public class NotifyActivity extends AppCompatActivity {

  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String identify = getIntent().getStringExtra(ChatActivity.IDENTIFY_KEY);
    TIMConversationType type =
        (TIMConversationType) getIntent().getSerializableExtra(ChatActivity.TYPE_KEY);

    if (!AppManagerUtil.getAppManager().isOpenActivity(MainActivity.class)) {
      startActivity(new Intent(this, MainActivity.class));
    }
    if (!identify.equals(Constants.SYSTEM_IDENTIFY)) {
      ChatActivity.navToChat(this, identify, type);
    } else {
      startActivity(new Intent(this, MainActivity.class));
      if (TIMManagerExt.getInstance().deleteConversationAndLocalMsgs(type, identify)) {
        RefreshEvent.getInstance().onRefresh();
      }
    }
    finish();
  }
}